package com.dhcc.core.framework.constant.state;

import com.dhcc.core.framework.util.CommonUtil;

/**
 * 资源分组的枚举
 * 
 * @ClassName: ResourceGroup
 * @Description: TODO
 * @author: cyf
 * @date: 2018年1月2日 上午9:13:46
 */
public enum ResourceGroup {

    // 后台
    BACKEND(0, "backend", "后台"),
    // 前台
    FRONT(1, "front", "前台"),
    // 接口
    API(2, "api", "接口");

    int code;
    String name;
    String message;

    ResourceGroup(int code, String name, String message) {
        this.code = code;
        this.name = name;
        this.message = message;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public static String valueOf(Integer status) {
        if (status == null) {
            return "";
        } else {
            for (ResourceGroup s : ResourceGroup.values()) {
                if (s.getCode() == status) {
                    return s.getMessage();
                }
            }
            return "";
        }
    }

    public static Integer getCodeByName(String name) {
        if (name == null) {
            return 0;
        } else {
            for (ResourceGroup s : ResourceGroup.values()) {
                if (CommonUtil.equals(s.getName(), name)) {
                    return s.getCode();
                }
            }
            return 0;
        }
    }
}
